import tkinter as tk
from tkinter import ttk

class BasePage(tk.Frame):
    """所有页面的基类，提供基本的显示和隐藏功能"""
    
    def __init__(self, parent, bg: str = "white", **kwargs):
        super().__init__(parent, bg=bg,** kwargs)
        
    def show(self) -> None:
        """显示页面"""
        self.pack(fill=tk.BOTH, expand=True)
    
    def hide(self) -> None:
        """隐藏页面"""
        self.pack_forget()


# 示例页面1 - 首页
class HomePage(BasePage):
    def __init__(self, parent):
        super().__init__(parent)
        self._init_ui()
    
    def _init_ui(self):
        """初始化首页UI"""
        # 标题
        title_label = tk.Label(
            self, 
            text="首页", 
            font=("Arial", 16, "bold"),
            bg="white"
        )
        title_label.pack(pady=30)
        
        # 描述文本
        desc_label = tk.Label(
            self, 
            text="这是一个模块化的Tkinter自定义窗口框架", 
            font=("Arial", 12),
            bg="white"
        )
        desc_label.pack(pady=10)
        
        # 示例按钮
        ttk.Button(
            self, 
            text="点击示例",
            command=self._on_example_click
        ).pack(pady=20)
    
    def _on_example_click(self):
        """示例按钮点击事件"""
        print("首页示例按钮被点击")


# 示例页面2 - 设置页
class SettingsPage(BasePage):
    def __init__(self, parent):
        super().__init__(parent)
        self._init_ui()
    
    def _init_ui(self):
        """初始化设置页UI"""
        # 标题
        title_label = tk.Label(
            self, 
            text="设置页面", 
            font=("Arial", 16, "bold"),
            bg="white"
        )
        title_label.pack(pady=30)
        
        # 设置选项
        option_frame = ttk.Frame(self)
        option_frame.pack(pady=10, fill=tk.X, padx=50)
        
        ttk.Label(option_frame, text="主题设置:").pack(side=tk.LEFT, padx=5)
        theme_combo = ttk.Combobox(option_frame, values=["浅色", "深色"], width=10)
        theme_combo.current(0)
        theme_combo.pack(side=tk.LEFT, padx=5)
        
        # 保存按钮
        ttk.Button(
            self, 
            text="保存设置",
            command=self._save_settings
        ).pack(pady=20)
    
    def _save_settings(self):
        """保存设置事件"""
        print("设置已保存")
